package com.czh.framework.security.web.service;

import com.czh.framework.security.web.UserDetailsEntity;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class UserDetailServiceImpl implements UserDetailsService {
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        //TODO 查用户。。。 权限信息啥的都要有哦
        List<GrantedAuthority> list = new ArrayList<>();
        GrantedAuthority grantedAuthority = new SimpleGrantedAuthority("test");
        list.add(grantedAuthority);
                UserDetailsEntity abc = new UserDetailsEntity(username,
                        "$2a$10$.9oRAuJ5ngiMGgsgYSJK2.CL77uxOwG65bEwASW6J122/6lVnAHuC",
                        list);
                return abc;
    }

    public static void main(String[] args) {
        BCryptPasswordEncoder cryptPasswordEncoder = new BCryptPasswordEncoder();
        final String root = cryptPasswordEncoder.encode("root");
        System.out.println(root);
    }
}
